function bonload(){
    checklike();
    checknotice();
    checkuri();
}
function checkuri(){
    var whref = window.location.href
    var ahref = document.getElementById("su").getElementsByTagName("a");
    for(let i = 0; i < ahref.length; i+=1 ){
        if(ahref[i].href == whref){
            ahref[i].style.display = "none";
            break
        }
    }
}
function checklike(){
    nowurl = window.location.href
    var likelist = localStorage.getItem("like");
    var objl = JSON.parse(likelist);
    if (objl !== null){
        for(let i = 0;i <= Object.keys(objl)[Object.keys.length-1]+1;i+=1){
            if( objl[i] == nowurl ){
                var exi = true;
                break
            }else{
                var exi =false;
            }
        }
    }
    if( exi == true){
        document.getElementById("like").style.color = "#1abc9c";
    }else{
        document.getElementById("like").style.color = "#152331";
    }
}
function searchf(state){
    if (state == "focus"){
        document.getElementById("sinput").setAttribute("placeholder","请输入搜索内容")
    }
    else{
        document.getElementById("sinput").setAttribute("placeholder","搜索")
    }
}
function savelike(uurl){
    var likelist = localStorage.getItem("like");
    var objl = JSON.parse(likelist);
    var boo = false;
    for(let i = 0;i <= Object.keys(objl)[Object.keys.length-1]+1;i+=1){
        if( objl[i] == uurl ){
            delete objl[String(i)];
            var objf = JSON.stringify(objl);
            localStorage.setItem("like", objf);
            document.getElementById("like").style.color = "#152331";
            return;
        }
    }
    if( objl[0] == null ){
        objl["0"] = uurl;
        var objf = JSON.stringify(objl);
        localStorage.setItem("like", objf);
        document.getElementById("like").style.color = "#1abc9c";
    }else if( boo == false ){
        var num = Object.keys(objl).length;
        objl[num] = uurl;
        var objf = JSON.stringify(objl);
        localStorage.setItem("like", objf);
        document.getElementById("like").style.color = "#1abc9c";
    }
}
function like(url){
    if(localStorage.getItem("like") == null){
        localStorage.setItem("like", "{}");
        savelike(url);
    }
    else{
        savelike(url);
    }
}

function checknotice(){
    ntc = document.getElementById("notcon").innerText
    if(ntc == "" || (ntc.length>0 && ntc.trim().length == 0) ){
        document.getElementById("nstru").style.display = "none"
    }else{
        let i = 0;
        document.getElementById("nstru").style.display = "block"
        var pro = setInterval(function(){
            i += 1;
            document.getElementById("notline").style.width = 50 - i*0.1 + "px";
        },20); 
        setTimeout(function(){document.getElementById("notice").style.display = "none";clearInterval(pro)},10000)
    }
}
function nothidden(){
    document.getElementById("notice").style.display = "none"
}
function recp(info,color,disabled) {
    document.getElementById("checkpwd").innerHTML= info ;
    document.getElementById("checkpwd").style.color = color;
    document.getElementById("ssubmit").disabled = disabled;
}
function checkpwd(){
    var pwd1 = document.getElementById("user_password").value;
    var pwd2 = document.getElementById("user_password_confirmation").value;
    if(pwd1 == pwd2 & pwd1.length >= 6 )
    {
        recp("密码一致且合规","#1abc9c",false)
    }else if(pwd1.length < 6){
        recp("密码过短，至少6个字符","#E84A07",true)
    }else if(pwd1 != pwd2){
        recp("两次输入内容不一致","#E84A07",true)
    }else{
        recp("密码不合规","#E84A07",true)
    }
}
function exp(ex){
    let before = document.getElementById("comtext").value
    document.getElementById("comtext").value = before + ex
}
function showexp(){
    if(document.getElementById("expsl").style.display == "none"){
        document.getElementById("expsl").style.display = "flex"
    }else{
        document.getElementById("expsl").style.display = "none"
    }
}